<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            width: 500px;
            height: 500px;
            background-color: pink;
        }

        .box2 {
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box1">
        <div class="box2">

        </div>
    </div>
    <script>
        const box1 = document.querySelector('.box1')
        const box2 = document.querySelector('.box2')
        // 事件捕获
        // document.addEventListener('click', function () { alert('我是老大') }, true)
        // box1.addEventListener('click', function () { alert('我是老2') }, true)
        // box2.addEventListener('click', function () { alert('我是老3') }, true)
        // 事件冒泡
        document.addEventListener('click', function () { alert('我是老大') })
        box1.addEventListener('click', function () { alert('我是老2') })
        box2.addEventListener('click', function (e) {
            alert('我是老3')
            e.stopPropagation()

        })
    </script>
</body>

</html>